package com.zb.zeus.system.api.factory;

import com.zb.zeus.common.core.constant.HttpStatus;
import com.zb.zeus.common.core.web.page.TableDataInfo;
import com.zb.zeus.system.api.RemoteOrgService;
import com.zb.zeus.system.api.domain.SysOrgBusiness;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.Collections;

/**
 * 组织服务降级服务
 *
 * @author zb.zeus
 */
@Component
public class RemoteOrgFallbackFactory implements FallbackFactory<RemoteOrgService> {
    private static final Logger log = LoggerFactory.getLogger(RemoteOrgFallbackFactory.class);

    @Override
    public RemoteOrgService create(Throwable throwable) {
        log.error("远程组织服务调用失败:", throwable);
        return new RemoteOrgService() {
            @Override
            public TableDataInfo list(SysOrgBusiness sysOrgBusiness) {
                TableDataInfo rspData = new TableDataInfo();
                rspData.setCode(HttpStatus.TIMEOUT);
                rspData.setRows(Collections.emptyList());
                rspData.setMsg("系统开小差, 请请稍后重试");
                rspData.setTotal(0L);
                return rspData;
            }
        };

    }
}
